<template>
	<!-- <view class="wrap" style="padding-bottom: 60px; background-color: rgb(242, 242, 242);"> -->
	<view class="wrap">
		<scroll-view class="scroll-list" scroll-y="true">
			<view class="selectCondition" style="background-color: white;" v-show="false">
				<view class="search" @click="searchOragins">
					<u-search :show-action="false" :clearabled="true" v-model="orgins" placeholder="请选择厂站"></u-search>
					<u-select v-model="showOragins" :list="station" @confirm="confirmOrgin"></u-select>
				</view>
				<view class="search" @click="selectDate">
					<u-search mode="single-column" :show-action="false" v-model="statuss"
						placeholder="请选择时间"></u-search>
					<u-calendar v-model="showDate" :mode="mode" @change="changeDate"></u-calendar>
				</view>
				<view class="selectItem">
					<u-button @click="searchOrderInfo" class="searchButton" type="primary" size="mini"
						shape="square">查询</u-button>
				</view>
			</view>
			<view class="navProgramm">
				<u-subsection :list="list" :current="current" @change="sectionChange"></u-subsection>
			</view>
			<!-- <view class="increase" v-show="this.current==0">
			<u-button type="primary" size="mini" :custom-style="customStyle" :ripple="true">新增</u-button>
		</view> -->

			<u-card v-for="item in orderInfo" :key="item.id" class="task-list-item" :show-head="false" :border="true"
				padding="20" margin="20rpx" :head-border-bottom="false">
				<view v-if="item.orderCode.substring(0, 4).toLowerCase() === 'rcxj'" class="" slot="body">
					<u-row gutter="16">
						<u-col span="12">
							<view class="apply-text"><text>{{item.orderCode}}</text></view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>巡检类型：</span>{{orderType}}</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>巡检时间：</span>{{item.inspectionTime}}</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>巡检人：</span>{{item.niceName}}</view>
						</u-col>
					</u-row>
				</view>
				<view v-else-if="item.orderCode.substring(0, 4).toLowerCase() === 'sbxj'" class="" slot="body">
					<u-row gutter="16">
						<u-col span="12">
							<view class="apply-text"><text>{{item.orderCode}}</text></view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>巡检类型：</span>{{orderType}}</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>巡检时间：</span>{{item.inspectionTime}}</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>巡检人：</span>{{item.niceName}}</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>填写时间：</span>{{item.updataTime}}</view>
						</u-col>
					</u-row>
				</view>
				<view v-else-if="item.orderCode.substring(0, 4).toLowerCase() === 'qyxj'" class="" slot="body">
					<u-row gutter="16">
						<u-col span="12">
							<view class="apply-text"><text>{{item.orderCode}}</text></view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>巡检类型：</span>{{orderType}}</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>巡检时间：</span>{{item.inspectionTime}}</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>巡检人：</span>{{item.niceName}}</view>
						</u-col>
					</u-row>
				</view>

				<view class="apply-list-foot" slot="foot" style="text-align: right;">
					<template v-if="item.niceName!=null">
						<span @click="viewDetail(item.id)" style="margin-right: 10px;">查看工单</span>
					</template>
					<template v-if="item.niceName==null">
						<span @click="editGD(item.id,item.orderCode)" style="margin-right: 10px;">编辑工单</span>
					</template>
				</view>

			</u-card>
			<u-divider v-if="orderInfo.length>0">已经到底了</u-divider>
		</scroll-view>
	</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [{
						name: '日常巡检'
					},
					{
						name: '设备巡检'
					},
					{
						name: '区域巡检'
					}
				],
				current: 0,
				customStyle: {
					color: 'white',
					backgroundColor: 'royalblue',
					transform: 'translate(600rpx, 20rpx)',
					marginBottom: '20rpx'
				},
				mode: 'range',
				endDate: '',
				startDate: '',
				showOragins: false,
				showDate: false,
				shows: true,
				show: false,
				orgins: '',
				statuss: '',
				station: [{
						value: '',
						label: ''
					},

				],
				originId: '',
				equipStatus: '',
				headOrgin: 0,
				//设备列表信息
				orderInfo: [],
				orderType: '',
				isZC: true
			}
		},

		onLoad(e) {
			this.getOrginInfo();
			this.getOrginList();
			this.originId = uni.getStorageSync('organId');
			this.orgins = '程桥污水厂';
			this.searchOrderInfo(e.current);
		},

		methods: {
			//分段器回调
			sectionChange(index) {
				this.current = index;
				this.orgins = ''
				this.orderInfo = []
				console.log(index, "index")
				this.getOrginList(index)
				this.searchOrderInfo(index)
			},
			search(value) {
				this.$u.toast('搜索内容为：' + value)
			},
			searchOragins() {
				this.showOragins = true;
				if (this.orgins.length != 0) {
					this.showOragins = false;
					this.originId = '';
				}
			},
			selectDate() {
				this.showDate = true;
			},
			confirmOrgin(e) {

				e.map((val, index) => {
					this.orgins = val.label;
					this.originId = val.value;
				})
			},

			//获取下拉厂站
			getOrginList() {
				if (this.current == 2) {
					this.$u.api.search({
							"algorithmProcessId": "getStationEq",
							"param": {
								"data": {
									"user_uuid": uni.getStorageSync('uuid')
								}
							}
						})
						.then(result => {

							let station = result.data.data.result || [];

							this.station = station.map(item => {
								return {
									value: item.id,
									label: item.structure_name
								};
							});
							if (station.length > 1) {
								//用户是集团的
								this.headOrgin = 1
							} else if (station.length == 1) {
								//用户属于分厂
								this.headOrgin = 0;
							}

						});
				} else {
					this.$u.api.getOrginList({
							"algorithmProcessId": "getptOrgin",
							"param": {
								"data": {
									"userUuid": uni.getStorageSync('uuid')
								}
							}
						})
						.then(result => {

							let station = result.data.data.result || [];

							this.station = station.map(item => {
								return {
									value: item.id,
									label: item.organ_name
								};
							});
							if (station.length > 1) {
								//用户是集团的
								this.headOrgin = 1
							} else if (station.length == 1) {
								//用户属于分厂
								this.headOrgin = 0;
							}

						});
				}

			},
			//查询巡检列表
			searchOrderInfo(index) {
				this.current = index ?? 0
				console.log('this.current', this.current)
				if (this.current == 0) {
					this.orderType = '日常巡检'
					this.$u.api.findRCXJGDBy({
							"algorithmProcessId": "day_check",
							"param": {
								"data": {
									"user_uuid": uni.getStorageSync('uuid'),
									// "organId": this.originId,
									"organId": uni.getStorageSync('organId'),
									"startdateRange_1692087804443": this.startDate,
									"enddateRange_1692087804443": this.endDate,
									"orderCode": '',
									"inspectorId": ''
								}
							}
						})
						.then(res => {

							let orderInfo = res.data.data.result || [];

							this.orderInfo = orderInfo.map(item => {
								return {
									id: item.id,
									orderCode: item.orderCode,
									inspectionTime: item.inspectionTime,
									niceName: item.niceName,
								};
							});

						});
				} else if (this.current == 1) {
					// console.log('this.current11111',this.originId)
					this.orderType = '设备巡检'
					this.$u.api.findSBXJGD({
							"algorithmProcessId": "equip_check",
							"param": {
								"data": {
									"user_uuid": uni.getStorageSync('uuid'),
									// "organId": this.originId,
									"organId": uni.getStorageSync('organId'),
									"startdateRange_1693381786946": this.startDate,
									"enddateRange_1693381786946": this.endDate,
									"orderCode": '',
									"inspectorId": ''
								}
							}
						})
						.then(res => {

							let orderInfo = res.data.data.result || [];

							this.orderInfo = orderInfo.map(item => {
								return {
									id: item.id,
									orderCode: item.order_code,
									inspectionTime: item.inspection_time,
									niceName: item.nice_name,
									updataTime: item.update_time
								};
							});

						});

				} else if (this.current == 2) {
					// console.log('this.current2222222',this.originId)
					this.orderType = '区域巡检'
					this.$u.api.findQYXJGD({
							"algorithmProcessId": "app_area_check",
							"param": {
								"data": {
									"user_uuid": uni.getStorageSync('uuid'),
									// "structure_uuid": this.originId,
									"structure_uuid": uni.getStorageSync('organId'),
									"startdateRange_1693275821819": this.startDate,
									"enddateRange_1693275821819": this.endDate,
									"inspection_code": '',
									"inspection_user": ''
								}
							}
						})
						.then(res => {

							let orderInfo = res.data.data.result || [];

							this.orderInfo = orderInfo.map(item => {
								return {
									id: item.id,
									orderCode: item.inspection_code,
									inspectionTime: item.inspection_date,
									niceName: item.nice_name
								};
							});

						});

				}


			},
			//查看工单
			viewDetail(id) {

				if (this.current == 0) {
					uni.navigateTo({
						url: '/pages/sys/order/pollingManage/detail?id=' + id
					});
				} else if (this.current == 1) {
					uni.navigateTo({
						url: '/pages/sys/order/pollingManage/equipDetail?id=' + id
					});
				} else {
					uni.navigateTo({
						url: '/pages/sys/order/pollingManage/areaDetail?id=' + id
					});
				}
			},
			//编辑工单
			editGD(id, code) {

				if (this.current == 0) {
					uni.navigateTo({
						url: '/pages/sys/order/pollingManage/editEverday?id=' + id
					});
				} else if (this.current == 1) {
					uni.navigateTo({
						url: '/pages/sys/order/pollingManage/editEquip?id=' + id
					});
				} else {
					uni.navigateTo({
						url: '/pages/sys/order/pollingManage/editArea?id=' + id + '&code=' + code
					});
				}
			},

			//日期选择的回调
			changeDate(e) {
				this.endDate = e.endDate;
				this.startDate = e.startDate;
				this.statuss = e.startDate + e.endDate;
			},
			//获取用户所属组织机构信息
			getOrginInfo() {
				this.$u.api.getOrginInfo({
						"algorithmProcessId": "getOrginInfo",
						"param": {
							"data": {
								"userUuid": uni.getStorageSync('uuid')
							}
						}
					})
					.then(result => {
						let orginInfo = result.data.data.result;
						this.isZC = orginInfo[1].isZC;
					});

			},

		},

	}
</script>
<style lang="scss" scoped>
	page {
		background-color: #fff;
	}

	.scroll-list {
		background-color: #fff;
	}


	.wrap .search {
		background: #ffffff;
	}

	.apply-text {
		font-size: 28rpx;
		color: #333333;
		height: 50rpx;

		span {
			color: #999999;
		}
	}


	.apply-list-foot {
		font-size: 28rpx;
	}


	.searchButton {
		height: 50rpx;
	}

	.selectCondition {

		.search {
			display: inline-block;
			width: 300rpx;

		}

		.selectItem {
			display: contents;
		}

	}

	.wrap .navProgramm {
		// white-space: nowrap;

		.item {
			width: 220rpx;
			height: 220rpx;
			display: inline-block;
			margin-right: 10rpx;
		}
	}

	.task-list-item {
		box-shadow:
			-4rpx -4rpx 6rpx rgba(0, 0, 0, 0.1),
			4rpx -4rpx 6rpx rgba(0, 0, 0, 0.1),
			-4rpx 4rpx 6rpx rgba(0, 0, 0, 0.1),
			4rpx 4rpx 6rpx rgba(0, 0, 0, 0.1) !important;
	}
</style>